<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item label="订阅名称">
              <a-input placeholder="请输入订阅名称" v-model="queryParam.fdName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="订阅说明">
              <a-input placeholder="请输入订阅说明" v-model="queryParam.fdExpain"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="reviewOk" type="primary" >复核通过</a-button>
      <a-button @click="repulse" type="primary" >打回</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('手工脱敏表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>
        <span>已选择</span>
        <a style="font-weight: 600">
          {{ selectedRowKeys.length }}
        </a>
        <span>项</span>
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:type}"
        @change="handleTableChange"
        :customRow="clickThenCheck">
        <!-- 字符串超长截取省略号显示-->
        <span slot="fdExpain" slot-scope="text">
          <j-ellipsis :value="text" :length="8" />
        </span>
        <span slot="action" slot-scope="text, record">
          <a href="javascript:;" @click="handleDetail(record)">详情</a>
              <a-divider type="vertical"/>
          <a href="javascript:;" @click="theHistoricalRecord(record.id)">历史记录</a>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->
    
    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="手工脱敏运行详情表" :key="refKeys[0]" :forceRender="true">
        <opersscTabdetail-List ref="OpersscTabdetailList"></opersscTabdetail-List>
      </a-tab-pane>
    </a-tabs>

    <!-- 表单区域 -->
    <operssc-tp-review-modal ref="modalForm" @ok="modalFormOk"/>
    <operssc-ar-history-modal ref="opersscArHistoryModal"></operssc-ar-history-modal>
  </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import OpersscTpReviewModal from './modules/OpersscTpReviewModal'
  import {deleteAction,getAction} from '@/api/manage'
  import OpersscTabdetailList from './OpersscTabdetailList'
  import OpersscTabdetailModal from './modules/OpersscTabdetailModal'
  import JEllipsis from "@/components/jeecg/JEllipsis";
  import OpersscArHistoryModal from '../operssc_orgnaization_of/modules/OpersscArHistoryModal'

  export default {
    name: "OpersscTpReviewList",
    mixins: [JeecgListMixin],
    components: {
      OpersscArHistoryModal,
      JEllipsis,
      OpersscTpReviewModal,
      OpersscTabdetailModal,
      OpersscTabdetailList,

    },
    data () {
      return {
        refKeys: ['opersscTabdetail', ],
        description: '手工脱敏表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender:function (t, r, index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '订阅名称',
            align:"center",
            dataIndex: 'fdName'
          },
          {
            title: '订阅说明',
            align:"center",
            dataIndex: 'fdExpain',
            scopedSlots: {customRender: 'fdExpain'},
          },
          {
            title: '是否脱敏',
            align:"center",
            dataIndex: 'fdDes_dictText'
          },
          {
            title: '应用工程',
            align:"center",
            dataIndex: 'fdProject_dictText'
          },
          {
            title: '开始日期',
            align:"center",
            dataIndex: 'fdRunDate'
          },
          {
            title: '结束日期',
            align:"center",
            dataIndex: 'fdRunEndDate'
          },

          {
            title: '脱敏目标库',
            align:"center",
            dataIndex: 'fdSource'
          },
         /* {
            title: '申请人',
            align:"center",
            dataIndex: 'fdApplyUser'
          },
          {
            title: '复合人',
            align:"center",
            dataIndex: 'fdCheckUser2'
          },*/

          {
            title: '状态',
            align:"center",
            dataIndex: 'fdStatus_dictText'
          },
       /*   {
            title: '是否发布到调度平台',
            align:"center",
            dataIndex: 'fdRelease_dictText'
          },*/

          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
 
        //操作url
        type: "radio",
        url: {
          list: "/rule/opersscTpReview/list",
          delete: "/rule/opersscTpReview/delete",
          deleteBatch: "/rule/opersscTpReview/deleteBatch",
          exportXlsUrl: "rule/opersscTpReview/exportXls",
          importExcelUrl: "rule/opersscTpReview/importExcel",
          reviewOk:"rule/opersscTpReview/updateSscidMigration",
          updateRepulse:"rule/opersscTpReview/updateRepulseSscid",
         },
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    created: function() {
      this.queryParamConfig = { 'fdName': 'like' }
    },
    methods: {
		clickThenCheck(record) {
        return {
          on: {
            click: () => {
              this.onSelectChange(record.id.split(","), [record]);
            }
          }
        };
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
        this.$refs.OpersscTabdetailList.getMain(this.selectedRowKeys[0]);
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.$refs.OpersscTabdetailList.queryParam.mainId = null;
        this.$refs.OpersscTabdetailList.loadData();
        this.$refs.OpersscTabdetailList.selectedRowKeys = [];
        this.$refs.OpersscTabdetailList.selectionRows = [];
      },

      handleDelete: function (id) {
        var that = this;
        deleteAction(that.url.delete, {id: id}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
            this.$refs.OpersscTabdetailList.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
      searchQuery:function(){
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.$refs.OpersscTabdetailList.queryParam.mainId = null;
        this.$refs.OpersscTabdetailList.loadData();
        this.$refs.OpersscTabdetailList.selectedRowKeys = [];
        this.$refs.OpersscTabdetailList.selectionRows = [];
        this.loadData();
      },
      theHistoricalRecord: function (id) {
        this.$refs.opersscArHistoryModal.edit(id);
        this.$refs.opersscArHistoryModal.title = "历史记录";
        this.$refs.opersscArHistoryModal.disableSubmit = true;
      },
      reviewOk: function () {
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a]
          }
          var that = this;
          this.$confirm({
            title: "确认复核",
            content: "是否复核通过?",
            onOk: function () {
              var  param = { ids: ids}
             getAction(that.url.reviewOk, param).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.$refs.OpersscTabdetailList.dataSource = null;
                } else {
                  that.$message.warning(res.message);
                }
              })
            }
          });
        }
      },
      repulse: function () {
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          var  fdStatus = "";
          for (var a = 0; a < this.selectionRows.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
            fdStatus  += this.selectionRows[a]["fdStatus"]
          }
          if (fdStatus == "3"){
           return alert("已是打回状态")
          }
          var that = this;
          this.$confirm({
            title: "确认打回",
            content: "是否打回?",
            onOk: function () {
              getAction(that.url. updateRepulse, {ids: ids}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();

                } else {
                  that.$message.warning(res.message);
                }
              });
            }
          });
        }
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>